****************
*** How street-level bureaucrats' traits affect community leaders' assessments of the government
*** Nico Ravanilla, Dotan Haim & Matthew Nanes
*** September 2024
*** Latest update: September 29, 2024 by Nico
*** Version 2 (JOP Final Replication)
*** Replication code
***************

/* Data accessed in this replication file:
PHI_MK4_processed_data_POLICE_wide.dta
PHI_MK4_processed_data_LEADERS_wide.dta
*/

*** Created in STATA/SE version 18.0

clear all
set more off

*** Install commands

*** Change to appropriate working directory (e.g.)

cd "~/Downloads/HRS_JOP2_Replication"

cd "~/Downloads/HRS_JOP2_Replication/1_Code"

*** Create log file

capture log close
log using bureaucrat_quality_logfile.log, replace

***************
* Main Tables *
***************


************
* Table A1 *
************

cd "~/Downloads/HRS_JOP2_Replication/2_Data"

use "Officer-Level Data.dta",clear


// Assign labels to traits raw scores
label variable psm "Public Service Motivation"
label variable ds "Cognitive Ability (Digit Span Score)"
label variable grit "Grit Scale"
label variable bfi "Big 5 Personality Index"
label variable extroversion "Extraversion"
label variable agreeable "Agreeableness"
label variable conscientious "Conscientiousness"
label variable neuroticism "Neuroticism"
label variable openness "Openness"

// Assign labels to independent variables
label variable psm_z_wmiss "Public Service Motivation"
label variable ds_z_wmiss "Cognitive Ability (Digit Span Score)"
label variable grit_z_wmiss "Grit Scale"
label variable bfi_z_wmiss "Big 5 Personality Index"

//Assign labels to officer-level controls
label variable female "Female"
label variable age "Age (in years)"
label variable years_served "Years in Service"
label variable rank_m "Officer Rank"
label variable educ1 "Less than College"
label variable educ2 "Completed College"
label variable educ3 "Completed Post-College"

// Assign label to dependent variable
label variable attendance "Attendance"

cd "~/Downloads/HRS_JOP2_Replication/3_Tables"

// Post descriptive statistics
estpost sum psm ds grit bfi extroversion agreeable conscientious neuroticism openness female age years_served rank_m educ1 educ2 educ3

// Export the descriptive statistics to a CSV file with custom column labels and custom rows at the bottom
esttab using "Table_A1.csv", cells("mean sd min max") ///
collabels("Mean" "St. Dev." "Min" "Max") label ///
not addnotes("Number of Senior Police Officers = 95") replace


************
* Table A7 *
************

keep if officer1!=.

global controls female age years_served rank_m educ1 educ2 o.educ3 ///
blank_age blank_years_served blank_rank_m

foreach i in attendance {

    // Run the regression
    reg `i' psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss ///
    blank_bfi blank_psm blank_ds blank_grit ///
    $controls, vce(cl sid_m)
    
    // Calculate the mean of the dependent variable and round it to 2 decimal points
    sum `i'
    local depvar_mean = round(r(mean), 0.01)
    
    // Store the estimates for this regression
    estimates store reg_`i'

    // Output the regression table, only keeping the specified variables, hiding the constant, and using labels
    if "`i'" == "attendance" {
        outreg2 [reg_`i'] using "Table_A7.xls", replace adjr2 tex dec(3) ///
        keep(psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss) ///
        addstat(Dep. Var. Mean, `depvar_mean') label
    }
    else {
        outreg2 [reg_`i'] using "Table_A7.xls", append adjr2 tex dec(3) ///
        keep(psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss) ///
        addstat(Dep. Var. Mean, `depvar_mean') label
    }
}


**************
* Figure A.1 *
**************

cd "~/Downloads/HRS_JOP2_Replication/4_Figures"

histogram attendance, density normal width(0.1) start(0) color(gs10) ///
title("Community Policing Attendance Rate") xlabel(0(0.2)1, labsize(medium)) ///
ylabel(, angle(0)) lwidth(medium) ///
xtitle("Attendance Rate")
graph export "histogram_attendance.png", as(png) replace


************
* Table A2 *
************

cd "~/Downloads/HRS_JOP2_Replication/2_Data"

use "Officer-CommunityLeader-Level Data.dta",clear


*Do summary stats after running the code lines above

estpost sum captain kagawad chieftanod age_e education_e employed_e income_e ///
reside_years_e male_e assets_roof_e years_served_e ///
c10_population c10_male c10_hhsize c10_ofw c10_education c10_age18_39 ///
c10_ms_single c10_catholic c10_ip c10_home_good npa_2015 dist_mps acrime_num_m ///
effort reliable responsive experience creative ///
trustworthy approach confident empathy overall ///
responsive_act_e polcaseserious_e polcap_timely_e ///
polint_corrupt_rc_e polint_quality_e satis_trust_e satis_general_e

// Assign labels to independent variables
label variable psm_z_wmiss "Public Service Motivation"
label variable ds_z_wmiss "Cognitive Ability (Digit Span Score)"
label variable grit_z_wmiss "Grit Scale"
label variable bfi_z_wmiss "Big 5 Personality Index"
label variable extroversion_z_wmiss "Extraversion"
label variable agreeable_z_wmiss "Agreeableness"
label variable conscientious_z_wmiss "Conscientiousness"
label variable neuroticism_z_wmiss "Neuroticism (Reverse-coded)"
label variable openness_z_wmiss "Openness"

// Assign labels to dependent variables
label variable effort "Effort"
label variable reliable "Reliability"
label variable responsive "Responsiveness"
label variable experience "Experience"
label variable creative "Creativity"
label variable trustworthy "Trustworthiness"
label variable approach "Approachability"
label variable confident "Confidence"
label variable empathy "Empathy"
label variable overall "Overall"

label variable responsive_act_e "Acts on citizen feedback"
label variable polcaseserious_e "Takes citizen report seriously"
label variable polcap_timely_e "Responds timely"
label variable polint_corrupt_rc_e "Not corrupt"
label variable polint_quality_e "Provides equal service"
label variable satis_trust_e "I trust the police"
label variable satis_general_e "Provides satisfactory service"

// Asign labels to barangay-level controls
label variable c10_population "Population"
label variable c10_male "Share of Male Residents"
label variable c10_hhsize "Average Household Size"
label variable c10_ofw "Share of Overseas Filipino Workers (OFW)"
label variable c10_education "Average Education"
label variable c10_age18_39 "Share Age"
label variable c10_ms_single "Share of Unmarried Residents"
label variable c10_catholic "Share Catholic Residents"
label variable c10_ip "Share of Indigenous Population"
label variable c10_home_good "Share of Home Goods"
label variable npa_2015 "Rebel Presence Rating in 2015"
label variable dist_mps "Average Distance From a Police Station (km)"
label variable acrime_num_m "Baseline Crime Rate"

// Asign labels to community leaders'-level controls
label variable captain "Barangay Kapitan = 1"
label variable kagawad "Barangay Kagawad = 1"
label variable chieftanod "Barangay Tanod = 1"
label variable age_e "Age (in years)"
label variable education_e "Educational Attainment"
label variable employed_e "Employment Status"
label variable income_e "Monthly Income (Pesos)"
label variable reside_years_e "Years in Residence"
label variable male_e "Male = 1"
label variable assets_roof_e "Assets"
label variable years_served_e "Years in Service"

//Assign labels to officer-level controls
label variable female "Female"
label variable age "Age (in years)"
label variable years_served "Years in Service"
label variable rank_m "Officer Rank"
label variable educ1 "Less than College"
label variable educ2 "Completed College"
label variable educ3 "Completed Post-College"

// Assign labels to Junior officer indexes of traits
label variable psm2_z_wmiss "Public Service Motivation (Junior)"
label variable ds2_z_wmiss "Cognitive Ability (Digit Span Score) (Junior)"
label variable grit2_z_wmiss "Grit Scale (Junior)"
label variable bfi2_z_wmiss "Big 5 Personality Index (Junior)"

global controls_bgy c10_population c10_male c10_hhsize c10_ofw c10_education c10_age18_39 ///
c10_ms_single c10_catholic c10_ip c10_home_good npa_2015 dist_mps acrime_num_m

global controls_bgy_respondents captain kagawad o.chieftanod age_e education_e employed_e income_e ///
reside_years_e male_e assets_roof_e years_served_e

global controls_officer female age years_served rank_m educ1 o.educ2 educ3

global controls_junior psm2_z_wmiss ds2_z_wmiss grit2_z_wmiss bfi2_z_wmiss


cd "~/Downloads/HRS_JOP2_Replication/3_Tables"

// Generate summary statistics
estpost sum captain kagawad chieftanod age_e education_e employed_e income_e ///
reside_years_e male_e assets_roof_e years_served_e ///
c10_population c10_male c10_hhsize c10_ofw c10_education c10_age18_39 ///
c10_ms_single c10_catholic c10_ip c10_home_good npa_2015 dist_mps acrime_num_m ///
effort reliable responsive experience creative ///
trustworthy approach confident empathy overall ///
responsive_act_e polcaseserious_e polcap_timely_e ///
polint_corrupt_rc_e polint_quality_e satis_trust_e satis_general_e

// Export the descriptive statistics to a CSV file with custom column labels and custom rows at the bottom
esttab using "Table_A2.csv", cells("mean sd min max") ///
collabels("Mean" "St. Dev." "Min" "Max") label ///
not addnotes("Number of Barangays = 95") replace


************
* Table A3 *
************

foreach i in effort reliable responsive experience creative trustworthy approach confident empathy overall {

    // Run the regression
    reg `i' psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss ///
    $controls_bgy, vce(cl bgy)
    
    // Perform the F-test
    test psm_z_wmiss = ds_z_wmiss = grit_z_wmiss = bfi_z_wmiss
    
    // Capture the p-value from the F-test and round it to 3 decimal points
    local p_value = round(r(p), 0.001)
    
    // Calculate the mean of the dependent variable and round it to 2 decimal points
    sum `i'
    local depvar_mean = round(r(mean), 0.01)
    
    // Store the estimates for this regression
    estimates store reg_`i'

    // Output the regression table, only keeping the specified variables, hiding the constant, and using labels
    if "`i'" == "effort" {
        outreg2 [reg_`i'] using "Table_A3.xls", replace tex dec(3) ///
        keep(psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss) ///
        addstat(F-test p-value, `p_value', Dep. Var. Mean, `depvar_mean') label
    }
    else {
        outreg2 [reg_`i'] using "Table_A3.xls", append tex dec(3) ///
        keep(psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss) ///
        addstat(F-test p-value, `p_value', Dep. Var. Mean, `depvar_mean') label
    }

    // Optionally display the rounded p-value and dependent variable mean in the console for confirmation
    di "F-test p-value for `i': `p_value', Dependent variable mean: `depvar_mean'"
}


************
* Table A8 *
************

foreach i in effort reliable responsive experience creative trustworthy approach confident empathy overall {

    // Run the regression
    reg `i' psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss, vce(cl bgy)
    
    // Perform the F-test
    test psm_z_wmiss = ds_z_wmiss = grit_z_wmiss = bfi_z_wmiss
    
    // Capture the p-value from the F-test and round it to 3 decimal points
    local p_value = round(r(p), 0.001)
    
    // Calculate the mean of the dependent variable and round it to 2 decimal points
    sum `i'
    local depvar_mean = round(r(mean), 0.01)
    
    // Store the estimates for this regression
    estimates store reg_`i'

    // Output the regression table, only keeping the specified variables, hiding the constant, and using labels
    if "`i'" == "effort" {
        outreg2 [reg_`i'] using "Table_A8.xls", replace tex dec(3) ///
        keep(psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss) ///
        addstat(F-test p-value, `p_value', Dep. Var. Mean, `depvar_mean') label
    }
    else {
        outreg2 [reg_`i'] using "Table_A8.xls", append tex dec(3) ///
        keep(psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss) ///
        addstat(F-test p-value, `p_value', Dep. Var. Mean, `depvar_mean') label
    }

    // Optionally display the rounded p-value and dependent variable mean in the console for confirmation
    di "F-test p-value for `i': `p_value', Dependent variable mean: `depvar_mean'"
}


************
* Table A9 *
************

foreach i in effort reliable responsive experience creative trustworthy approach confident empathy overall {

    // Run the regression
    reg `i' psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss ///
    $controls_officer $controls_bgy_respondents $controls_bgy  $controls_junior, vce(cl bgy)
    
    // Perform the F-test
    test psm_z_wmiss = ds_z_wmiss = grit_z_wmiss = bfi_z_wmiss
    
    // Capture the p-value from the F-test and round it to 3 decimal points
    local p_value = round(r(p), 0.001)
    
    // Calculate the mean of the dependent variable and round it to 2 decimal points
    sum `i'
    local depvar_mean = round(r(mean), 0.01)
    
    // Store the estimates for this regression
    estimates store reg_`i'

    // Output the regression table, only keeping the specified variables, hiding the constant, and using labels
    if "`i'" == "effort" {
        outreg2 [reg_`i'] using "Table_A9.xls", replace tex dec(3) ///
        addstat(F-test p-value, `p_value', Dep. Var. Mean, `depvar_mean') label
    }
    else {
        outreg2 [reg_`i'] using "Table_A9.xls", append tex dec(3) ///
        addstat(F-test p-value, `p_value', Dep. Var. Mean, `depvar_mean') label
    }

    // Optionally display the rounded p-value and dependent variable mean in the console for confirmation
    di "F-test p-value for `i': `p_value', Dependent variable mean: `depvar_mean'"
}


************
* Table A4 *
************

foreach i in effort reliable responsive experience creative trustworthy approach confident empathy overall {

    // Run the regression
    reg `i' psm_z_wmiss ds_z_wmiss grit_z_wmiss ///
    extroversion_z_wmiss agreeable_z_wmiss conscientious_z_wmiss neuroticism_z_wmiss openness_z_wmiss ///
    $controls_bgy, vce(cl bgy)
    
    // Perform the F-test
    test extroversion_z_wmiss = agreeable_z_wmiss = conscientious_z_wmiss = neuroticism_z_wmiss = openness_z_wmiss
    
    // Capture the p-value from the F-test and round it to 3 decimal points
    local p_value = round(r(p), 0.001)
    
    // Calculate the mean of the dependent variable and round it to 2 decimal points
    sum `i'
    local depvar_mean = round(r(mean), 0.01)
    
    // Store the estimates for this regression
    estimates store reg_`i'

    // Output the regression table, only keeping the specified variables, hiding the constant, and using labels
    if "`i'" == "effort" {
        outreg2 [reg_`i'] using "Table_A4.xls", replace tex dec(3) ///
        keep(extroversion_z_wmiss agreeable_z_wmiss conscientious_z_wmiss neuroticism_z_wmiss openness_z_wmiss) ///
        addstat(F-test p-value, `p_value', Dep. Var. Mean, `depvar_mean') label
    }
    else {
        outreg2 [reg_`i'] using "Table_A4.xls", append tex dec(3) ///
        keep(extroversion_z_wmiss agreeable_z_wmiss conscientious_z_wmiss neuroticism_z_wmiss openness_z_wmiss) ///
        addstat(F-test p-value, `p_value', Dep. Var. Mean, `depvar_mean') label
    }

    // Optionally display the rounded p-value and dependent variable mean in the console for confirmation
    di "F-test p-value for `i': `p_value', Dependent variable mean: `depvar_mean'"
}


************
* Table A5 *
************

foreach i in responsive_act polcaseserious polcap_timely polint_corrupt_rc polint_quality satis_trust satis_general {

    // Run the regression
    reg `i'_e psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss `i'_m ///
    $controls_bgy, vce(cl bgy)
    
    // Perform the F-test
    test psm_z_wmiss = ds_z_wmiss = grit_z_wmiss = bfi_z_wmiss
    
    // Capture the p-value from the F-test and round it to 3 decimal points
    local p_value = round(r(p), 0.001)
    
    // Calculate the mean of the dependent variable and round it to 2 decimal points
    sum `i'_e
    local depvar_mean = round(r(mean), 0.01)
    
    // Store the estimates for this regression
    estimates store reg_`i'

    // Output the regression table, only keeping the specified variables, hiding the constant, and using labels
    if "`i'" == "responsive_act" {
        outreg2 [reg_`i'] using "Table_A5.xls", replace tex dec(3) ///
        keep(psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss) ///
        addstat(F-test p-value, `p_value', Dep. Var. Mean, `depvar_mean') label
    }
    else {
        outreg2 [reg_`i'] using "Table_A5.xls", append tex dec(3) ///
        keep(psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss) ///
        addstat(F-test p-value, `p_value', Dep. Var. Mean, `depvar_mean') label
    }

    // Optionally display the rounded p-value and dependent variable mean in the console for confirmation
    di "F-test p-value for `i': `p_value', Dependent variable mean: `depvar_mean'"
}


************
* Table A10 *
************

foreach i in responsive_act polcaseserious polcap_timely polint_corrupt_rc polint_quality satis_trust satis_general {

    // Run the regression
    reg `i'_e psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss `i'_m, vce(cl bgy)
    
    // Perform the F-test
    test psm_z_wmiss = ds_z_wmiss = grit_z_wmiss = bfi_z_wmiss
    
    // Capture the p-value from the F-test and round it to 3 decimal points
    local p_value = round(r(p), 0.001)
    
    // Calculate the mean of the dependent variable and round it to 2 decimal points
    sum `i'_e
    local depvar_mean = round(r(mean), 0.01)
    
    // Store the estimates for this regression
    estimates store reg_`i'

    // Output the regression table, only keeping the specified variables, hiding the constant, and using labels
    if "`i'" == "responsive_act" {
        outreg2 [reg_`i'] using "Table_A10.xls", replace tex dec(3) ///
        keep(psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss) ///
        addstat(F-test p-value, `p_value', Dep. Var. Mean, `depvar_mean') label
    }
    else {
        outreg2 [reg_`i'] using "Table_A10.xls", append tex dec(3) ///
        keep(psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss) ///
        addstat(F-test p-value, `p_value', Dep. Var. Mean, `depvar_mean') label
    }

    // Optionally display the rounded p-value and dependent variable mean in the console for confirmation
    di "F-test p-value for `i': `p_value', Dependent variable mean: `depvar_mean'"
}


************
* Table A11 *
************

foreach i in responsive_act polcaseserious polcap_timely polint_corrupt_rc polint_quality satis_trust satis_general {

    // Run the regression
    reg `i'_e psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss `i'_m ///
    $controls_officer $controls_bgy_respondents $controls_bgy  $controls_junior, vce(cl bgy)
    
    // Perform the F-test
    test psm_z_wmiss = ds_z_wmiss = grit_z_wmiss = bfi_z_wmiss
    
    // Capture the p-value from the F-test and round it to 3 decimal points
    local p_value = round(r(p), 0.001)
    
    // Calculate the mean of the dependent variable and round it to 2 decimal points
    sum `i'_e
    local depvar_mean = round(r(mean), 0.01)
    
    // Store the estimates for this regression
    estimates store reg_`i'

    // Output the regression table, only keeping the specified variables, hiding the constant, and using labels
    if "`i'" == "responsive_act" {
        outreg2 [reg_`i'] using "Table_A11.xls", replace tex dec(3) ///
		drop(`i'_m) ///
        addstat(F-test p-value, `p_value', Dep. Var. Mean, `depvar_mean') label
    }
    else {
        outreg2 [reg_`i'] using "Table_A11.xls", append tex dec(3) ///
        drop(`i'_m) ///
		addstat(F-test p-value, `p_value', Dep. Var. Mean, `depvar_mean') label
    }

    // Optionally display the rounded p-value and dependent variable mean in the console for confirmation
    di "F-test p-value for `i': `p_value', Dependent variable mean: `depvar_mean'"
}


************
* Table A6 *
************

foreach i in responsive_act polcaseserious polcap_timely polint_corrupt_rc polint_quality satis_trust satis_general {

    // Run the regression
    reg `i'_e psm_z_wmiss ds_z_wmiss grit_z_wmiss `i'_m ///
    extroversion_z_wmiss agreeable_z_wmiss conscientious_z_wmiss neuroticism_z_wmiss openness_z_wmiss ///
    $controls_bgy, vce(cl bgy)
    
    // Perform the F-test
    test extroversion_z_wmiss = agreeable_z_wmiss = conscientious_z_wmiss = neuroticism_z_wmiss = openness_z_wmiss
    
    // Capture the p-value from the F-test and round it to 3 decimal points
    local p_value = round(r(p), 0.001)
    
    // Calculate the mean of the dependent variable and round it to 2 decimal points
    sum `i'_e
    local depvar_mean = round(r(mean), 0.01)
    
    // Store the estimates for this regression
    estimates store reg_`i'

    // Output the regression table, only keeping the specified variables, hiding the constant, and using labels
    if "`i'" == "responsive_act" {
        outreg2 [reg_`i'] using "Table_A6.xls", replace tex dec(3) ///
        keep(extroversion_z_wmiss agreeable_z_wmiss conscientious_z_wmiss neuroticism_z_wmiss openness_z_wmiss) ///
        addstat(F-test p-value, `p_value', Dep. Var. Mean, `depvar_mean') label
    }
    else {
        outreg2 [reg_`i'] using "Table_A6.xls", append tex dec(3) ///
        keep(extroversion_z_wmiss agreeable_z_wmiss conscientious_z_wmiss neuroticism_z_wmiss openness_z_wmiss) ///
        addstat(F-test p-value, `p_value', Dep. Var. Mean, `depvar_mean') label
    }

    // Optionally display the rounded p-value and dependent variable mean in the console for confirmation
    di "F-test p-value for `i': `p_value', Dependent variable mean: `depvar_mean'"
}


*************
* Table A12 *
*************

// Generate the attriters variable
gen attriters = 1 if empathy == .
replace attriters = 0 if empathy != .

// Create a matrix to store the results
preserve
postfile handle str20 varname mean_attriters mean_nonattriters N_attriters N_nonattriters diff_means pvalue using "Table_A12.dta", replace

// Loop through each variable and calculate the necessary statistics
foreach i in captain kagawad chieftanod age_e education_e employed_e income_e ///
reside_years_e male_e assets_roof_e years_served_e {

    // Perform t-test by attriters
    ttest `i', by(attriters)

    // Capture the means, difference, and p-value
    local mean_attriters = r(mu_1)
    local mean_nonattriters = r(mu_2)
    local N_attriters = r(N_1)
    local N_nonattriters = r(N_2)
    local diff_means = round(r(mu_1) - r(mu_2), 0.001)
    local pvalue = r(p)

    // Post the results into the table
    post handle ("`i'") (`mean_attriters') (`mean_nonattriters') (`N_attriters') (`N_nonattriters') (`diff_means') (`pvalue')
}

// Close the postfile
postclose handle

// Export the results to a CSV file
use "Table_A12.dta", clear
export delimited using "Table_A12.csv", replace
restore


*************
* Table A13 *
*************

// Run the correlation command
corr psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss ///
female age years_served rank_m educ1 educ2 educ3

// Capture the correlation matrix into a matrix
matrix corr_matrix = r(C)

// Set the Excel file to output the results
putexcel set "Table_A13.xlsx", replace

// Export the correlation matrix into Excel starting from cell B2 (shifted to the right by one column)
putexcel B2=matrix(corr_matrix)

// Add the column headers (shifted by one to start from B1)
putexcel B1=("Public Service Motivation") C1=("Delegation Skills") D1=("Grit") E1=("Big Five Inventory") F1=("Female") G1=("Age") H1=("Years Served") I1=("Rank") J1=("Education Level 1") K1=("Education Level 2") L1=("Education Level 3")

// Add row labels manually (starting in A2)
local varlist "psm_z_wmiss ds_z_wmiss grit_z_wmiss bfi_z_wmiss female age years_served rank_m educ1 educ2 educ3"
local i = 2
foreach var of local varlist {
    putexcel A`i' = "`var'"
    local ++i
}

// Close the Excel output
putexcel save


log close
